package com.wwcom.darteagle.util;

import java.util.List;

import com.wwcom.darteagle.model.GlobalAppData;
import com.wwcom.darteagle.model.MatchPlayer;

import android.os.Bundle;

public class Posts {
	public static final int TWITTER= 0;
	public static final int FACEBOOK= 1;
    
	//messages 
	public static String goodScore(int type, Bundle extras) {
		String message= "";
		switch (type) {
		case TWITTER:
			message= extras.getString("player")+" scores "+
					Integer.toString(extras.getInt("score"))+", great shot! "+
					" - "+matchScore(type)+" #darteagle";
		}
		return message;
	}
	
	public static String legComplete(int type, Bundle extras) {
		String message= "";
		switch (type) {
		case TWITTER:
			message+= extras.getString("player")+" you require "+Integer.toString(extras.getInt("score"))+" - ";
			message+= "Yeees! Game, shot and the leg "+extras.getString("player")+" - "+
					matchScore(type)+" #darteagle";
		}
		return message;
	}
	
	public static String setComplete(int type, Bundle extras) {
		String message= "";
		switch (type) {
		case TWITTER:
			message+= extras.getString("player")+" you require "+Integer.toString(extras.getInt("score"))+" - ";
			message+= "Yeees! Game, shot and the set "+extras.getString("player")+" - "+
					matchScore(type)+" #darteagle";
		}
		return message;
	}	

	public static String matchComplete(int type, Bundle extras) {
		String message= "";
		switch (type) {
		case TWITTER:
			message+= extras.getString("player")+" you require "+Integer.toString(extras.getInt("score"))+" - ";
			message+= "Yeees! Game, shot and the match "+extras.getString("player")+" - "+
					matchScore(type)+" #darteagle";
		}
		return message;
	}	
	private static String matchScore(int type) {
		GlobalAppData gd= GlobalAppData.getSingletonInstance();
		String message= "";
		switch (type) {
		case TWITTER:		
			List<MatchPlayer> matchPlayers= gd.match.getMatchPlayers(); 
			int numPlayers=  matchPlayers.size();
			if (gd.match.getNumSets() > 0) {
				for (int i= 0; i<numPlayers; ++i) {
					message+= matchPlayers.get(i).getPlayer().getName()+" "+
						Integer.toString(matchPlayers.get(i).getNumSets())+" ("+
						Integer.toString(matchPlayers.get(i).getNumLegs())+")";
					if (i < numPlayers-1) {
						message+= ", ";
					}
				}
			} else {
				for (int i= 0; i<numPlayers; ++i) {
					message+= matchPlayers.get(i).getPlayer().getName()+" "+
						Integer.toString(matchPlayers.get(i).getNumLegs());
					if (i < numPlayers-1) {
						message+= ", ";
					}
				}
			}
		}
		return message;
	}
}
